#ifndef _TestSpcoPersist_TEST_INCLUDE_H_
#define _TestSpcoPersist_TEST_INCLUDE_H_

#include <cppunit\TestFixture.h>
#include <cppunit\extensions\HelperMacros.h>
#include "SpcoPersist.h"
#include "Spco.h"
#include "DatabaseBase.h"

using namespace PDMS::PDMSDBIF;
using namespace PDMS::PDMSFrame;
using namespace PDMS::SpecFrame;

class TestSpcoPersist:public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE( TestSpcoPersist );
	CPPUNIT_TEST( testCreate );
	CPPUNIT_TEST( testUpdate );
	CPPUNIT_TEST( testRetrieve );
	CPPUNIT_TEST_SUITE_END();
public:
	TestSpcoPersist();
	virtual ~TestSpcoPersist();
	void testCreate();
	void testUpdate();
	void testRetrieve();
};

void TestSpcoPersist::testCreate()
{
	Spco spco;
	spco.Id( UeObjectId(0,1000) );
	spco.SetAllo( true );
	spco.SetAngle( 10.02 );
	spco.SetBltID( 12 );
	spco.SetBltref( "TaoRubbish" );
	spco.SetCatID( 132 );
	spco.SetCatref( "TaoGabbage" );
	spco.SetCmpID( 123 );
	spco.SetCmpref( "Uesoft" );
	spco.SetDetID( 1234 );
	spco.SetEdge( "Hangjie" );
	spco.SetGType( "valve" );
	spco.SetMatxtID( 10 );
	spco.SetPbor0( 1.2 );
	spco.SetPbor1( 1.3 );
	spco.SetPbor2( 1.4 );
	spco.SetPbor3( 1.5 );
	spco.SetShop( false );
	spco.SetSpecName( "A150" );
	spco.SetSType( "Global" );
	spco.Name( "Lobby" );

	SpcoPersist sppersist;
	DatabaseBase db( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	db.DataSource( "D:\\SpecificationTemplate.mdb" );
	
	sppersist.SetDatabase( &db );
	sppersist.Create( &spco );
	db.UpdateAll();
	db.CloseAll();
}

void TestSpcoPersist::testUpdate()
{
	Spco spco;
	spco.Id( UeObjectId(0,1000) );
	spco.SetAllo( false );
	spco.SetAngle( 100.02 );
	spco.SetBltID( 120 );
	spco.SetBltref( "T0aoRubbish" );
	spco.SetCatID( 1320 );
	spco.SetCatref( "Ta0oGabbage" );
	spco.SetCmpID( 1230 );
	spco.SetCmpref( "Ue0soft" );
	spco.SetDetID( 12340 );
	spco.SetEdge( "Hangj0ie" );
	spco.SetGType( "valve0" );
	spco.SetMatxtID( 100 );
	spco.SetPbor0( 1.02 );
	spco.SetPbor1( 1.03 );
	spco.SetPbor2( 1.04 );
	spco.SetPbor3( 1.05 );
	spco.SetShop( true );
	spco.SetSpecName( "B150" );
	spco.SetSType( "Glob0al" );
	spco.Name( "Lobby0" );

	SpcoPersist sppersist;
	DatabaseBase db( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	db.DataSource( "D:\\SpecificationTemplate.mdb" );
	
	sppersist.SetDatabase( &db );
	sppersist.Update( &spco );
	db.UpdateAll();
	db.CloseAll();
}

void TestSpcoPersist::testRetrieve()
{
	Spco* pco = new Spco;
	pco->Id( UeObjectId(0,1000) );
	SpcoPersist sppersist;
	DatabaseBase db( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	db.DataSource( "D:\\SpecificationTemplate.mdb" );
	
	sppersist.SetDatabase( &db );
	//sppersist.Retrieve( ( Persistable* )( pco ) );
	Persistable* p = pco;
	sppersist.Retrieve( p );
	db.CloseAll();
}
#endif
